//
//  SHVisitorViewController.swift
//  SHWeibo3
//
//  Created by teacher on 16/7/19.
//  Copyright © 2016年 teacher. All rights reserved.
//

import UIKit

class SHVisitorViewController: UIViewController {
    
    
    // 判断用户是否登录
    var isLogin: Bool = SHUserAccountViewModel.sharedTools.isLogin
    // 访客视图view
    var visitorView: SHVisitorView?
    
    
    // MARK: - 监听方法
    @objc private func loginClick(){
        // 加载授权界面
        let oauthVc = SHOAuthViewController()
        presentViewController(UINavigationController(rootViewController: oauthVc), animated: true, completion: nil)
    }
    
    override func loadView() {
//        if isLogin {
//            view = tableView
//        }else {
//            visitorView = SHVisitorView()
//            view = visitorView
//        }
        isLogin ? (view = tableView) : setupVisitorView()
    }
    // MARK: -  设置访客视图
    func setupVisitorView(){
        visitorView = SHVisitorView()
        visitorView?.closure = {[weak self] in
            self?.loginClick()
        }
        view = visitorView
        setupNav()
    }
    
    // MARK: - 设置导航按钮
    func setupNav(){
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "登录", target: self, action: "loginClick")
        navigationItem.rightBarButtonItem = SHBarButtonItem(title: "注册", target: self, action: "loginClick")

    }

    override func viewDidLoad() {
        super.viewDidLoad()

    }
    // MARK: -  懒加载控件
    lazy var tableView: UITableView = UITableView()
    
   
}
